From a141c6625369099496fe8711ca7eb444eab884e0 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Mon, 19 Apr 2010 01:07:20 -0400 Subject: [PATCH] Added testextendedlayout2.c to tests. This test is a collection of builder files which demonstrate the added features of natural sizes and height-for-width geometry; so far it only contains 3 cases, more to come... --- tests/Makefile.am | 3 + tests/testextendedlayout2.c | 344 ++++++++++++++++++++++++++++++++++++ 2 files changed, 347 insertions(+) create mode 100644 tests/testextendedlayout2.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 50b131ab36..3830aa1183 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -44,6 +44,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \ testentrycompletion \ testentryicons \ testextendedlayout \ + testextendedlayout2 \ testfilechooser \ testfilechooserbutton \ testframe \ @@ -131,6 +132,7 @@ testellipsise_DEPENDENCIES = $(TEST_DEPS) testentrycompletion_DEPENDENCIES = $(TEST_DEPS) testentryicons_DEPENDENCIES = $(TEST_DEPS) testextendedlayout_DEPENDENCIES = $(TEST_DEPS) +testextendedlayout2_DEPENDENCIES = $(TEST_DEPS) testfilechooser_DEPENDENCIES = $(TEST_DEPS) testfilechooserbutton_DEPENDENCIES = $(TEST_DEPS) testgtk_DEPENDENCIES = $(TEST_DEPS) @@ -194,6 +196,7 @@ testellipsise_LDADD = $(LDADDS) testentrycompletion_LDADD = $(LDADDS) testentryicons_LDADD = $(LDADDS) testextendedlayout_LDADD = $(LDADDS) +testextendedlayout2_LDADD = $(LDADDS) testfilechooser_LDADD = $(LDADDS) testfilechooserbutton_LDADD = $(LDADDS) testgtk_LDADD = $(LDADDS) diff --git a/tests/testextendedlayout2.c b/tests/testextendedlayout2.c new file mode 100644 index 0000000000..02f93e5331 --- /dev/null +++ b/tests/testextendedlayout2.c @@ -0,0 +1,344 @@ +#include + + +typedef struct { + const gchar *name; + const gchar *tooltip; + const gchar *interface; + GtkWidget *window; +} TestInterface; + + +/* These strings were generated with: + * + * IFS=""; while read line; do echo -n \"; echo -n $line | sed -e 's|\"|\\"|g'; echo \"; done < file.glade + */ +TestInterface interfaces[] = { + { + "Ellipsizing Labels", + "Demonstrates how labels will request a natural size in a horizontal space", + "" + " " + " " + " " + " 450" + " 50" + " " + " " + " True" + " " + " " + " True" + " Some labels do ellipsize" + " end" + " " + " " + " " + " " + " " + " " + " 0" + " " + " " + " " + " " + " True" + " but some" + " end" + " " + " " + " " + " " + " " + " " + " 1" + " " + " " + " " + " " + " True" + " do not at all" + " " + " " + " " + " " + " " + " " + " " + " 2" + " " + " " + " " + " " + " " + "", + NULL + }, + + { + "Wrapping Label", + "Demonstrates how a wrapping label can require a height contextual to its allocated width", + "" + " " + " " + " " + " 12" + " 300" + " " + " " + " True" + " True" + " " + " " + " True" + " " + " " + " True" + " A short static label." + " " + " " + " " + " " + " " + " 0" + " " + " " + " " + " " + " True" + " This is a really long label for the purpose of testing line wrapping is working correctly in conjunction with height-for-width support in GTK+" + " True" + " 30" + " " + " " + " " + " " + " " + " False" + " 1" + " " + " " + " " + " " + " True" + " True" + " True" + " " + " " + " True" + " A really really long label inside a button to demonstrate height for width working inside buttons" + " True" + " 25" + " " + " " + " " + " " + " " + " " + " " + " False" + " 2" + " " + " " + " " + " " + " False" + " False" + " " + " " + " " + " " + " True" + " This label can shrink." + " center" + " " + " " + " " + " " + " " + " " + " True" + " True" + " " + " " + " " + " " + " " + "", + NULL + }, + + { + "Horizontal Box", + "Demonstrates how a horizontal box can calculate the collective height for an allocated width", + "" + " " + " " + " " + " 200" + " 600" + " " + " " + " True" + " True" + " " + " " + " True" + " " + " " + " True" + " " + " " + " True" + " True" + " True" + " False" + " " + " " + " True" + " A button that wraps." + " True" + " 10" + " " + " " + " " + " " + " " + " " + " " + " False" + " 0" + " " + " " + " " + " " + " True" + " Lets try to set some text start to wrap up in this hbox and see if the height-for-width is gonna work !" + " True" + " 30" + " " + " " + " " + " " + " " + " 1" + " " + " " + " " + " " + " False" + " 0" + " " + " " + " " + " " + " A button that expands in the container" + " True" + " True" + " True" + " False" + " " + " " + " 1" + " " + " " + " " + " " + " False" + " False" + " " + " " + " " + " " + " True" + " This label can shrink." + " center" + " " + " " + " " + " " + " " + " " + " True" + " True" + " " + " " + " " + " " + " " + "", + NULL + }, + +}; + + +static void +test_clicked (GtkWidget *button, + TestInterface *interface) +{ + if (!interface->window) + { + GtkBuilder *builder = gtk_builder_new (); + + gtk_builder_add_from_string (builder, interface->interface, -1, NULL); + interface->window = (GtkWidget *)gtk_builder_get_object (builder, "window"); + + g_signal_connect (interface->window, "delete_event", + G_CALLBACK (gtk_widget_hide_on_delete), NULL); + } + + gtk_widget_show (interface->window); +} + + +static GtkWidget * +create_window (void) +{ + GtkWidget *window, *vbox, *button; + gint i; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + vbox = gtk_vbox_new (FALSE, 6); + + gtk_container_set_border_width (GTK_CONTAINER (window), 8); + + gtk_widget_show (vbox); + gtk_container_add (GTK_CONTAINER (window), vbox); + + for (i = 0; i < G_N_ELEMENTS (interfaces); i++) + { + button = gtk_button_new_with_label (interfaces[i].name); + + gtk_widget_set_tooltip_text (button, interfaces[i].tooltip); + + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (test_clicked), &interfaces[i]); + + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + gtk_widget_show (button); + } + + return window; +} + + + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + + gtk_init (&argc, &argv); + + window = create_window (); + + g_signal_connect (window, "delete-event", + G_CALLBACK (gtk_main_quit), window); + + gtk_widget_show (window); + + gtk_main (); + + return 0; +} -- 2.30.2